﻿<cfcomponent>
<cfscript>
DB = 'chinalaohu';
</cfscript>

	<cffunction name="uuidgetuid" access="public" returntype="query">
    <cfquery datasource="#DB#" name="uuidgetuid">
    select uid,mobile,realname,urank,ustatus
    from user_base
    where muuid = '#uuid#'
    </cfquery>
		<cfreturn uuidgetuid>
	</cffunction>


<cffunction name="userCreditAuth" access="remote" returntype="numeric">
	<!---会员信息验证获得的信用额度--->
  <cfquery datasource="#DB#" name="user_auth">
  select uid,m_auth,e_auth,i_auth
  from user_base
  where uid = '#uid#'
  </cfquery>
  <cfscript>
	CreditLimit = 0;
	//手机号
	if (user_auth.m_auth eq 1){
		CreditLimit = CreditLimit + 1000;
	}
	//EMAIL
	if (user_auth.e_auth eq 1){
		CreditLimit = CreditLimit + 1000;
	}
	//身份证
	if (user_auth.i_auth eq 1){
		CreditLimit = CreditLimit + 3000;
	}
	</cfscript>
	<cfreturn CreditLimit>
</cffunction>


<cffunction name="userCredit" access="remote" returntype="numeric">
	<cfif not isdefined('CreditLimit') or not isnumeric(CreditLimit)>
    <cfinvoke method="userCreditAuth" returnvariable="CreditLimit" uid="#uid#" />
  </cfif>
	<!---保证金X50--->
  <cfinvoke component="deposit" method="getbzjvalue" returnvariable="userdeposit" uid="#uid#" />
  <cfscript>
  if (userdeposit gt 0){
		CreditLimit = CreditLimit + userdeposit * 50;
	}
  </cfscript>
	<cfreturn CreditLimit>
</cffunction>



<!---会员出价额度（可用）--->
<cffunction name="userCreditLimit" access="remote" returntype="numeric">
	<!---会员信息验证获得的信用额度--->
  <cfquery datasource="#DB#" name="user_auth">
  select uid,m_auth,e_auth,i_auth
  from user_base
  where muuid = '#UUID#'
  </cfquery>

	<cfif not isdefined('CreditLimit') or not isnumeric(CreditLimit)>
    <cfinvoke method="userCredit" returnvariable="CreditLimit" uid="#user_auth.uid#" />
  </cfif>
  
  <!---出代理价--->
  <cfquery datasource="#DB#" name="userbidproxy">
  select aid
  from auction_userbidproxy
  where uid = #user_auth.uid#
  <cfif isdefined('aid')>AND aid <> #aid#</cfif>
   and limittime > now()
  </cfquery>
  <cfif userbidproxy.recordcount gt 0>
    <cfquery datasource="#DB#" name="usersumbidproxy">
    select sum(bidproxy) as sumbidproxy
    from auction_userbidproxy
    where uid = #user_auth.uid# and limittime > now()
		<cfif isdefined('aid')>AND aid <> #aid#</cfif>
    </cfquery>
    <cfscript>
		if (isnumeric(usersumbidproxy.sumbidproxy)){
  	CreditLimit = CreditLimit - usersumbidproxy.sumbidproxy;
		}
    </cfscript>
  </cfif>
  <!---未出代理价的竞拍--->
  <cfquery datasource="#DB#" name="userbid">
  select sum(bid) as sumbid 
  from auction_userlastbid
  WHERE
  is_bid = 1
  AND uid = #user_auth.uid# and wonid=0
  <cfif userbidproxy.recordcount gt 0>AND aid NOT IN (#valuelist(userbidproxy.aid)#)</cfif>
  <cfif isdefined('aid')>AND aid <> #aid#</cfif>
  </cfquery>
  <cfif isnumeric(userbid.sumbid)>
		<cfset CreditLimit = CreditLimit - userbid.sumbid>
  </cfif>
	<!---入单未支付--->
  <cfquery datasource="#DB#" name="unpaywon">
  SELECT
  Sum(auction_userlastbid.bid) as sumupw
  FROM
  auction_userlastbid
  INNER JOIN auction_userwon ON auction_userwon.wonID = auction_userlastbid.wonID
  INNER JOIN auction_userwonpaid ON auction_userwonpaid.paidID = auction_userwon.paidID
  WHERE
  auction_userlastbid.uid = #user_auth.uid# AND
  auction_userlastbid.wonID > 0 AND
  auction_userwonpaid.pay_status < 2
  <cfif isdefined('aid')>AND auction_userlastbid.aid <> #aid#</cfif>
  </cfquery>
  <cfif isnumeric(unpaywon.sumupw)>
		<cfset CreditLimit = CreditLimit - unpaywon.sumupw>
  </cfif>
  
	<cfreturn CreditLimit>
</cffunction>



<!---会员拍卖额度--->
<cffunction name="userCreditLimit0" access="remote" returntype="numeric">
	<!---会员信息验证获得的信用额度--->
  <cfquery datasource="#DB#" name="user_auth">
  select uid,m_auth,e_auth,i_auth
  from user_base
  where muuid = '#UUID#'
  </cfquery>
  <cfscript>
	CreditLimit = 0;
	//手机号
	if (user_auth.m_auth eq 1){
		CreditLimit = CreditLimit + 1000;
	}
	//EMAIL
	if (user_auth.e_auth eq 1){
		CreditLimit = CreditLimit + 1000;
	}
	//身份证
	if (user_auth.i_auth eq 1){
		CreditLimit = CreditLimit + 3000;
	}
	</cfscript>
  <!---保证金X50--->
  
  
  
  
  <!---出代理价--->
  <cfquery datasource="#DB#" name="userbidproxy">
  select aid
  from auction_userbidproxy
  where uid = #user_auth.uid#
  <cfif isdefined('aid')>AND aid <> #aid#</cfif>
  </cfquery>
  <cfif userbidproxy.recordcount gt 0>
    <cfquery datasource="#DB#" name="usersumbidproxy">
    select sum(bidproxy) as sumbidproxy
    from auction_userbidproxy
    where uid = #user_auth.uid#
		<cfif isdefined('aid')>AND aid <> #aid#</cfif>
    and limittime > now()
    </cfquery>
    <cfscript>
		if (isnumeric(usersumbidproxy.sumbidproxy)){
  	CreditLimit = CreditLimit - usersumbidproxy.sumbidproxy;
		}
    </cfscript>
  </cfif>
  <!---未出代理价的竞拍--->
  <cfquery datasource="#DB#" name="userbid">
  select sum(bid) as sumbid
  from auction_userbid
  WHERE
  is_bid = 1
  AND uid = #user_auth.uid#
  <cfif userbidproxy.recordcount gt 0>AND aid NOT IN (#valuelist(userbidproxy.aid)#)</cfif>
  <cfif isdefined('aid')>AND aid <> #aid#</cfif>
  </cfquery>
  <cfif isnumeric(userbid.sumbid)>
		<cfset CreditLimit = CreditLimit - userbid.sumbid>
  </cfif>
  
	<cfreturn CreditLimit>
</cffunction>


<!---会员资料完整度--->
<cffunction name="userDataIntegrity" access="remote" returntype="string">
<cfstoredproc procedure="pro_get_userinfo_percent" dataSource="#DB#"> 
    <cfprocparam type="IN" CFSQLType="cf_sql_varchar" value="#uid#" > 
    <cfprocparam type="OUT" CFSQLType="cf_sql_integer" variable="res"> 
</cfstoredproc> 
  <cfreturn res>
</cffunction>



  
  
</cfcomponent>